package com.xb.loan.encryptor.comm;


import com.xb.loan.encryptor.classloader.ClassLoaderConfig;
import com.xb.loan.encryptor.comm.protocol.Protocol;
import com.xb.loan.encryptor.comm.protocol.impl.DecoderImpl;
import com.xb.loan.encryptor.comm.protocol.impl.EncoderImpl;

import java.io.IOException;
import java.net.UnknownHostException;

public class BasicSocketFactory {
	
	private Protocol protocol;
	
	public BasicSocketFactory(){
		
		protocol = new Protocol();
		protocol.setDecoder(new DecoderImpl());
		protocol.setEncoder(new EncoderImpl());
		
	}
	
	public BasicSocketClient getInstance() throws NumberFormatException, UnknownHostException, IOException {
		
		ClassLoaderConfig config = ClassLoaderConfig.getConfig("crypt");
		
		BasicSocketClient client = new BasicSocketClient(config.getServerIp(), Integer.parseInt(config.getPort()));
		
		client.setKeepAlive(false);
		client.setProtocol(protocol);
		client.setSoTimeout(Integer.parseInt(config.getSotimeout()));
		
		return client;
	}
	
}
